<?php

namespace app\model\user;

use app\base\BaseModel;

/**
 * 模型-user
 * Class BannerModel
 * @package app\model
 */
class UserAddressModel extends BaseModel
{

    protected $name = 'user_address';

    /**
     * 范围查询-user_id
     * @param $query
     * @param $user_id
     */
    public function scopeUserId($query, $user_id)
    {
        if (!empty($user_id)) {
            $query->where('user_id', trim($user_id));
        }
    }

    /**
     * 获取分页列表
     * @param $user_id
     * @param $current_page
     * @param $list_rows
     * @param string $field
     * @return array
     */
    public function getPageData($user_id, $current_page, $list_rows, $field = '*')
    {
        $dataList = $this
            ->field($field)
            ->UserId($user_id)
            ->order('id', 'desc')
            ->paginate(['page' => $current_page, 'list_rows' => $list_rows], false);
        $current = $dataList->currentPage();
        $total = $dataList->total();
        $limit = $dataList->listRows();
        $ret = ['total' => $total, 'current' => $current, 'limit' => $limit, 'dataList' => $dataList->items()];
        return $ret;
    }
}